package cn.credit.ms.dbms;

import java.util.List;
import java.util.Map;

public interface GenericDAO {
	/**
	 * @return long of the global unique seq_sid
	 */
	long nextSid();
	
	/**
	 * @param sname the sequence name
	 * @return long of the give seq;
	 */
	long nextSeq(final String sname);

	/**
	 * @param sql if no parameters
	 * @return the only record, null if not exists, only, exception if more than one;
	 */
	<T> Map<String, T> getOnly(final String sql);
	/**
	 * @param sql
	 * @param parameters of preparedStatement
	 * @return the only record, null if not exists, only, exception if more than one;
	 */
   <T> Map<String, T> getOnly(final String sql, final Object value) ;

	/**
	 * @param sql if no parameters
	 * @return  the record List, empty if not found;
	 */
   <T> List<Map<String, T>> getList(final String sql);
	/**
	 * @param sql
	 * @param parameters of preparedStatement
	 * @return  the record List, empty if not found;
	 */
	<T> List<Map<String, T>> getList(final String sql, final Object value);
	
	/**
	 * @param sql of insert or update Statement
	 * @return  affected rows;
	 */
    int execute(final String sql);
    
    long insertAndGetSid(String sql, Object value);
	
	/**
	 * @param sql of insert or update Statement
	 * @param parameters of preparedStatement
	 * @return  affected rows;
	 */
    int execute(final String sql, final Object value);

}
